#!perl -T

use strict;
use warnings;
use Test::More tests => 12;
use Test::BoostUnit qw(:ALL);


my %h1 = (
ONE => 1,
TWO => 1,
THREE => 1,
FOUR => 1,
FIVE => 1,
SIX => 1,
SEVEN => 1,
);

my %h2 = (
ONE => 2,
TWO => 3,
THREE => 2,
FOUR => 0,
FIVE => 2,
SIX => 0,
SEVEN => 2,
);

my %h3 = (
ONE => 2,
TWO => 3,
THREE => 1,
FOUR => 1,
FIVE => 2,
SIX => 0,
SEVEN => 2,
);


my %h4 = (
ONE => 2,
TWO => 3,
THREE => 1,
FOUR => 1,
FIVE => 2,
SIX => 0,
SEVEN => 2,
EIGHT => 1,
NINE => 0,
);

ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2}) - 1.42857) < 0.0001, "No Matches" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h1}) - 0) < 0.0001, "All Matches" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h3}) - 1.142857) < 0.0001, "2 out of 7 Matches" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h4}) - 1.142857) < 0.0001, "2 out of 7 Matches - extra keys" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h3,VECTOR2 => \%h4}) - 0) < 0.0001, "All Matches - extra keys" );

ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'Mean',})               - -0.57143) < 0.001, "Mean Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'MeanL1Norm',})         - 1.142857) < 0.001, "MeanL1Norm Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'RelativeMean',})       - -0.09524) < 0.001, "RelativeMean Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'RelativeL1Norm',})     - 0.666667) < 0.001, "RelativeL1Norm Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'RelativeMaxL1Norm',})        - 1) < 0.001, "RelativeMaxL1Norm Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'MaxL1Norm',})  - 2) < 0.001, "MaxL1Norm Error" );
ok(abs(calculateErrorMetricForTwoHashes({VECTOR1 => \%h1,VECTOR2 => \%h2, METRIC => 'RMS',})                - 1.195228) < 0.001, "RMS Error" );

